<?php

namespace addons\Merchants\backend\controllers;

use Yii;
use common\enums\StatusEnum;
use common\models\base\SearchModel;
use common\models\merchant\SettleAccountRecords;

/**
 * 结算管理
 *
 * Class SettleAccountController
 * @package addons\Merchants\backend\controllers
 * @author YiiFrame <21931118@qq.com>
 */
class SettleAccountRecordsController extends BaseController
{
    /**
     * @var SettleAccountRecords
     */
    public $modelClass = SettleAccountRecords::class;

    /**
     * @return string
     * @throws \yii\web\NotFoundHttpException
     */
    public function actionIndex()
    {
        $searchModel = new SearchModel([
            'model' => $this->modelClass,
            'scenario' => 'default',
            'partialMatchAttributes' => [], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC,
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        $dataProvider->query
            ->andWhere(['is_issue' => StatusEnum::DISABLED])
            ->with(['merchant']);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
        ]);
    }

    /**
     * @return string
     * @throws \yii\web\NotFoundHttpException
     */
    public function actionList()
    {
        $searchModel = new SearchModel([
            'model' => $this->modelClass,
            'scenario' => 'default',
            'partialMatchAttributes' => [], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC,
            ],
            'pageSize' => $this->pageSize
        ]);

        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        $dataProvider->query
            ->andWhere(['is_issue' => StatusEnum::ENABLED])
            ->andWhere(['settle_account_id' => Yii::$app->request->get('settle_account_id')])
            ->with(['merchant']);

        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
        ]);
    }
}